using System;
using System.Diagnostics;

namespace HgAdapter
{
	public class HgLog: HgCommand
	{
		static readonly string[] changeSetSeparator = new string[]{"\n\n"};
		
		public string Run()
		{
			string output = GetHgStatusOutput();
			ParseOutput(output);
			return output;
		}

		private static void ParseOutput(string output)
		{
			string[] changeSets = output.Split(changeSetSeparator, StringSplitOptions.None);
			foreach (string changeSet in changeSets)
			{
				string[] changeSetAttributes = changeSet.Split('\n');
			}
		}

		private static string GetHgStatusOutput()
		{
			string result;

			string saveCurrentDirectory = Environment.CurrentDirectory;
			Environment.CurrentDirectory = ProjectCommitInfo.Instance.ProjectPath;

			Process hgProcess = Process.Start(HgStatusStartInfo("log -f"));
			hgProcess.WaitForExit(1000);
			result = hgProcess.StandardOutput.ReadToEnd();

			Environment.CurrentDirectory = saveCurrentDirectory;

			return result;
		}
	}
}
